layui.extend({
    authMock: "mock/auth",
})
    .define(["authMock", "http", "apiAuth", "MD5", "store"], function (exports) {
        var MD5 = layui.MD5,
            http = layui.http.service,
            authMock = layui.authMock,
            store = layui.store,
            api = layui.apiAuth;
        authMock();
        var authServices = {
            /**
             * @author: ares
             * @date: 2020/2/2 19:55
             * @description: 登录
             * @param {string}account
             * @param {string}password
             * @param {string}code
             */
            loginMock: function (account, password, code) {
                var data = {
                    account: account,
                    password: password,
                    code: code,
                };
                return http(api.loginMock, {method: "post", data: data});
            },
            /**
             * @author: ares
             * @date: 2020/2/2 19:56
             * @description: 退出登录
             */
            logoutMock: function () {
                return http(api.logoutMock).then(function (res) {
                    window.location.replace("./index.html");
                });
            },

            /**
             * @author: ares
             * @date: 2020/2/2 19:55
             * @description: 登录
             * @param {string}mobile
             * @param {string}pwd
             */
            login: function (mobile, pwd) {
                var params = {
                    mobile: mobile,
                    pwd: MD5.hex_md5(pwd + "{cloud}"),
                };
                return http(api.login, {params: params}).then(function (res) {
                    store.remove("currentUserInfo"); //删除治疗师的信息, 两端同时在一个浏览器登录会相互影响(治疗师和医生部分页面共享)
                    return res;
                });
            },
            /**
             * @author: ares
             * @date: 2020/2/2 19:56
             * @description: 退出登录
             */
            logout: function () {
                return http(api.logout, {method: "delete"}).then(function (res) {
                    top.location.replace("/index.html");
                });
            },
            /**
             * @author: ares
             * @date: 2020/12/15 10:35
             * @description: 修改密码
             * @param {string}pwd  旧密码
             * @param {string}new_pwd  新密码
             * @returns {Promise.<TResult>|*}
             */
            modifyPwd: function (pwd, new_pwd) {
                var params = {
                    pwd: MD5.hex_md5(pwd + "{cloud}"),
                    new_pwd: MD5.hex_md5(new_pwd + "{cloud}"),
                };
                return http(api.modifyPwd, {method: "put", params: params});
            },
            /**
             * @author: ares
             * @date: 2020/12/15 10:41
             * @description: 是否为治疗师(治疗师不能登录系统)
             * @param {string}login_account  账号
             * @returns {Promise.<TResult>|*}
             */
            isTherapist: function (login_account) {
                var params = {
                    login_account: login_account,
                };
                return http(api.isTherapist, {params: params});
            },
        };

        exports("authServices", authServices);
    });
